<?php
session_start();
require('../conn.php');
require('../functions.php');
require('../QueryList.class.php');
require('admin.php');
if ($_POST) {
    $url = $_POST['long'];
    $codeArr = explode("#",$_POST['code']);
    $code = $codeArr[0];
    $money = $codeArr[1];
//    echo $url."<br>".$code."<br>".$code_pp;
//    exit;
    $html =get_contentsM($url);
//    $reg = [
//        'title' => ['p','text','-.clearfix'],
//        'video' => ['.video_player','html'],
//    ];
    $reg = [
        'title' => ['p:first','text'],
        'video' => ['.video_player','html'],
        'pic' => ['.vid_img','html'],
    ];
    $hj = QueryList::Query($html,$reg);
    $arr = $hj->jsonArr;
    $title = $arr[0]['title'];
    //替换video的时间戳和ssig
    $videoStr = $arr[0]['video'];
    $str = 'yx=&amp;refer=weibo_app" preload="preload">';
    $replaceStr = cut($videoStr,"?",'""');
    $content = str_replace($replaceStr,$str,$videoStr);
//    echo $content;exit;
    //取出缩略图
    $picDiv = $arr[0]['pic'];
    $pic=cut($picDiv,'data-url="','"');
    $query = "select * from `article` where `title`='{$title}' limit 1";
    $row = $mysql->query($query);
    if (!$row) {
        $arr = array('top' => -1, 'title' => $title, 'content' => $content, 'pic' => $pic, 'type' => 2,'code' => $code,  'day' => date("Y-m-d", time()),'flag' => 1);
        $value = arr2s($arr);
        $sql = "insert into `article`(top,title,content,pic,type,code,day,flag) VALUES (-1,$title,$content,$pic,2,$code,date(\"Y-m-d\",time()),1)";
        $mysql->query("insert into `article` {$value}");
        $id = mysql_insert_id();
        if ($id !== 0) {
            echo "<script>location.href='edit_article.php?id={$id}'</script>";
            exit;
        } else {
            echo '<script>alert(\'发布失败\');location.href=\'weixin.php\'</script>';
            exit;
        }
    } else {
        echo "<script>location.href='edit_article.php?id={$row[0]['id']}'</script>";
        exit;
    }
} ?>






<?php include('head.php') ?>
<div class="container-fluid">
    <div class="row-fluid">
        <?php
        include('left.php'); ?>
        <div class="span10">
            <h1 class="page-title">秒拍视频导入</h1>
            <div class="well">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#home" data-toggle="tab">发布</a></li>
                    <li><a href="http://www.kan25.com/new.html" target="_blank">更多视频</a></li>
                </ul>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <form id="tab" action="miaopai.php" method="post">
                            <label>标签</label>
                            <select id="code" name="code" >
                                <?php
                                $row_code = $mysql->query("select * from `wyq_title` where type=2 ");
                                foreach ($row_code as $v_code) {
                                    $number=$v_code['code'];
                                    echo "<option value=\"{$number}#\">[$number] {$v_code['content']}</option>";
                                } ?>
                            </select>
                            <label>秒拍视频网址：</label>
                            <input type="text" value="" style="width:500px" name="long"><br/>
                            <p>例如：<code>http://m.miaopai.com/show/channel/kHiL5IxgQNCNxfxBYRzXJQ__</code>
                            </p>
                            <p>备注：<code>请筛选秒拍视频，并用浏览器切换成手机模式复制网址</code>
                            </p>
                            <label></label>
                            <button class="btn btn-primary"><i class="icon-save"></i> 提交</button>
                        </form>
                    </div>
                    <div class="tab-pane fade" id="profile">
                        <form id="tab2">
                            <label>New Password</label>
                            <input type="password" class="input-xlarge">
                            <div>
                                <button class="btn btn-primary">Update</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="lib/bootstrap/js/bootstrap.js"></script>


</body>
</html>